<template>
	<view class="me-container">
		<!-- 顶部个人信息区域 -->
		<view class="user-info">
			<image class="user-avatar" src="/static/default-avatar.png" mode="aspectFit"></image>
			<view class="user-details">
				<text class="username">{{username}}</text>
			</view>
			<view class="settings-icon">
				<image src="/static/settings.png" mode="aspectFit"></image>
			</view>
		</view>

		<!-- 列表项 -->
		<view class="menu-list">
			<view class="menu-item">
				<text class="menu-text">我的订单</text>
				<view class="arrow-right"></view>
			</view>
			<view class="menu-item">
				<text class="menu-text">收货地址</text>
				<view class="arrow-right"></view>
			</view>
			<view class="menu-item">
				<text class="menu-text">客服中心</text>
				<view class="arrow-right"></view>
			</view>
			<view class="menu-item-login">
				<text class="menu-text-login" @click="gologin">{{usertoken? '退出登录' : '去登录'}}</text>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		onLoad,
		onShow
	} from "@dcloudio/uni-app"
	import {
		ref
	} from 'vue';
	let username = ref("")
	let usertoken = ref("")

	onLoad((option) => {
		user()
	})
	onShow(() => {
		usertoken.value = uni.getStorageSync("token")
	})
	const user = () => {
		let token = uni.getStorageSync("token")
		let userid = uni.getStorageSync("userid")
		uni.request({
			url: "https://www.xuzhixiang.top:30001/api/user/info",
			method: "GET",
			header: {
				token: token
			},
			data: {
				userid
			},
			success: (res) => {
				console.log(res.data.data[0].username)
				console.log(res)
				username.value = res.data.data[0].username
			}
		})

	}

	function gologin() {
		console.log("dianji")
		let token = uni.getStorageSync("token")
		let userid = uni.getStorageSync("userid")
		if (token) {
			uni.removeStorageSync("token")
			uni.removeStorageSync("userid")
			usertoken.value = uni.getStorageSync("token")
		} else {
			uni.navigateTo({
				url: "/pages/login/login"
			})
		}
	}
</script>

<style>
	/* 全局样式 */
	.me-container {
		background-color: #f5f5f5;
		min-height: 100vh;
	}

	/* 顶部个人信息区域 */
	.user-info {
		display: flex;
		align-items: center;
		padding: 40rpx 30rpx;
		background-color: #07c160;
		color: #fff;
	}

	.user-avatar {
		width: 140rpx;
		height: 140rpx;
		border-radius: 50%;
		background-color: #fff;
		border: 4rpx solid rgba(255, 255, 255, 0.3);
	}

	.user-details {
		flex: 1;
		margin-left: 30rpx;
	}

	.username {
		display: block;
		font-size: 36rpx;
		font-weight: bold;
	}

	.user-id {
		display: block;
		font-size: 28rpx;
		margin-top: 10rpx;
		opacity: 0.9;
	}

	.settings-icon {
		width: 40rpx;
		height: 40rpx;
	}

	.settings-icon image {
		width: 100%;
		height: 100%;
	}

	/* 菜单列表 */
	.menu-list {
		margin-top: 20rpx;
		background-color: #fff;
	}

	.menu-item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 30rpx;
		border-bottom: 1rpx solid #eee;
	}

	.menu-item-login {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 300rpx;
		padding-top: 500rpx !important;
		color: red;
		border-bottom: 1rpx solid #eee;
	}

	.menu-item:last-child {
		border-bottom: none;
	}

	.menu-text {
		font-size: 32rpx;
		color: #333;
	}

	.arrow-right {
		width: 16rpx;
		height: 16rpx;
		border-top: 2rpx solid #999;
		border-right: 2rpx solid #999;
		transform: rotate(45deg);
	}
</style>